<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>商品列表</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <link rel="stylesheet" href="../../layui/css/layui.css" media="all"/>
    <link rel="stylesheet" href="//at.alicdn.com/t/font_tnyc012u2rlwstt9.css" media="all"/>
    <link rel="stylesheet" href="../../css/news.css" media="all"/>
    <script type="text/javascript" src="../../../layui/layui.js"></script>
    <script type="text/javascript" src="../../../js/common.js"></script>
</head>
<body>
<blockquote class="layui-elem-quote news_search">
    <form class="layui-form" action="">
        <div class="layui-inline">
            <div class="layui-inline">
                <input name="name" id="name" placeholder="学生" class="layui-input search_input">
            </div>
            <a class="layui-btn search_btn" lay-submit lay-filter="search" id="search">查询</a>
        </div>
    </form>
</blockquote>
<div class="layui-form news_list table1" style="display: block">
    <table id="cycle" lay-filter="test" width="100%"></table>
</div>
<div class="layui-form news_list table2" style="display: none">
    <a class="layui-btn return_btn" style="background-color:#5FB878;float: right;margin-right:20px">返回列表</a>
    <table id="availableProjects" lay-filter="test" width="100%"></table>
</div>
<div id="page"></div>
<!--<script type="text/javascript" src="scheduleList.js"></script>-->
<!-- 数据格式化模板 -->
<script type="text/html" id="priority">
    {{#  if(d.priority == 0){ }}
    优选队列
    {{#  } else if(d.priority == 1){ }}
    候选队列
    {{#  }else if(d.priority == 3){ }}
    至少做0次
    {{#  } }}
</script>
<script type="text/html" id="isFinished">
    {{#  if(d.isFinished == 0){ }}
    否
    {{#  } else if(d.isFinished == 1){ }}
    是
    {{#  } }}
</script>
<!-- 表格操作模板 -->
<script type="text/html" id="editBar">
    <a class="layui-btn layui-btn-xs" lay-event="update">修改</a>
    <a class="layui-btn layui-btn-xs" lay-event="view">查看项目</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
</script>
<script type="text/javascript">
    layui.config({
        base: "js/"
    }).use(['form', 'layer', 'jquery', 'laypage', 'table', 'laytpl'], function () {
        var form = layui.form,
            layer = parent.layer === undefined ? layui.layer : parent.layer,
            laypage = layui.laypage,
            table = layui.table;
        $ = layui.jquery;

        $.post

        table.render({
            elem: '#cycle'
            , url: baseKnowledgeUrl+'/child/courseCycle/find' //数据接口
            , page: true //开启分页
            , limit: 10
            , id: 'cycle'
            , cellMinWidth: 120
            , cols: [[ //表头
                {type: 'checkbox'}// 开启复选框
                , {field: 'id', title: 'ID'}
                , {field: 'name', title: '学生'}
                , {field: 'classTimes', title: '课时数'}
                , {field: 'beginDate', title: '周期开始时间'}
                , {field: 'endDate', title: '周期结束时间'}
                , {field: 'age', title: '年龄'}
                , {field: 'grade', title: '年级'}
                , {field: 'visualBreadth', title: '视觉广度'}
                , {field: 'visualErrorRate', title: '视觉辨别失误率'}
                , {field: 'thinkingScore', title: '思维分数'}
                , {field: 'visualIntegrationAge', title: '视动年龄等级'}
                , {field: 'trainingTimes', title: '周期内训练总项目次数'}
                , {field: 'visualMemory', title: '视觉记忆能力'}
                , {field: 'hearingBreadth', title: '听觉广度'}
                , {field: 'hearingMemory', title: '视觉记忆'}
                , {field: 'stage', title: '阶段'}
                , {field: 'remarks', title: '备注信息'}
                , {fixed: 'right', title: '操作',width:178, align: 'center', toolbar: '#editBar'}
            ]]
        });

        // 监听排序
        table.on('sort(test)', function (obj) {
            table.reload('cycle', {
                initSort: obj
                , where: {
                    field: obj.field //排序字段
                    , order: obj.type //排序方式
                }
            });
        });

        // 监听操作
        table.on('tool(test)', function (obj) {
            var data = obj.data;
            if (obj.event === 'update') {
                //layer.msg('ID：' + data.id + ' 修改');
                var index = layui.layer.open({
                    title: "修改课程",
                    type: 2,
                    content: "childCourseCycleUpdateOrView.html",
                    success: function (layero, index) {
                        var body = layui.layer.getChildFrame('body', index);
                        body.find('#id').val(data.id);
                        body.find('#childId').val(data.childId);
                        body.find('#name').val(data.name);
                        body.find('#beginDate').val(data.beginDate);
                        body.find('#endDate').val(data.endDate);
                        body.find('#age').val(data.age);
                        body.find('#grade').val(data.grade);
                        body.find('#visualBreadth').val(data.visualBreadth);
                        body.find('#visualErrorRate').val(data.visualErrorRate);
                        body.find('#thinkingScore').val(data.thinkingScore);
                        body.find('#visualIntegrationAge').val(data.visualIntegrationAge);
                        body.find('#trainingTimes').val(data.trainingTimes);
                        body.find('#visualMemory').val(data.visualMemory);
                        body.find('#hearingBreadth').val(data.hearingBreadth);
                        body.find('#hearingMemory').val(data.hearingMemory);
                        body.find('#stage').val(data.stage);
                        body.find('#remarks').val(data.remarks);


                        // 渲染表单
                        setTimeout(function () {
                            layui.layer.tips('点击此处返回课程周期列表', '.layui-layer-setwin .layui-layer-close', {
                                tips: 3
                            });
                        }, 500)
                    }
                });
                layui.layer.full(index);
            } else if (obj.event === 'del') {
                layer.confirm('真的删除行么', function (index) {
                    $.ajax({
                        url: baseKnowledgeUrl+'/child/courseCycle/delete/' + data.id,
                        type: 'GET',
                        success: function (data) {
                            if (data.statusCode === '0000') {
                                layer.msg(data.message);
                                location.reload();
                            } else {
                                layer.msg(data.message);
                            }
                        }
                    });
                    layer.close(index);
                });
            }else if (obj.event === 'view') {
                $(".table1")[0].style.display = "none";
                $(".table2")[0].style.display = "block";
                table.render({
                    elem: '#availableProjects'
                    , url: baseKnowledgeUrl+'/visualProject/find?cycleId='+data.id //数据接口
                    , page: true //开启分页
                    , limit: 10
                    , id: 'availableProjects'
                    , cellMinWidth: 120
                    , cols: [[ //表头
                        {type: 'checkbox'}// 开启复选框
                        , {field: 'id', title: 'ID'}
                        , {field: 'projectCode', title: '项目编码'}
                        , {field: 'trainingTimes', title: '可以训练总次数'}
                        , {field: 'trainedTimes', title: '已训练次数'}
                        , {field: 'priority', title: '优先级类型', templet: '#priority'}
                        , {field: 'isFinished', title: '是否终止训练',templet: '#isFinished'}
                        , {field: 'trajectory', title: '轨迹'}
                    ]]
                });

            }
        });


        // 表格重载
        form.on('submit(search)', function (data) {
            console.log(data.field);
            table.reload('cycle', {
                page: {
                    curr: 1 //重新从第 1 页开始
                }
                , where: data.field
            });
        });

        //添加项目
        $(".return_btn").click(function () {
            $(".table1")[0].style.display = "block";
            $(".table2")[0].style.display = "none";
        });

    });
</script>
</body>
</html>